from enum import Enum


class ErrorCodeEnum(Enum):
    """
    错误码枚举
    """
    # ========== 通用错误 ========== #
    OK = (0, '操作成功')
    SUCCESS = (0, '操作成功')

    ERROR = (-1, '操作失败')
    FAIL = (-1, '操作失败')

    SYSTEM_BUSY = (1001, '系统繁忙')

    # ========== http错误 ========== #
    BAD_REQUEST = (400, '错误的请求')
    UNAUTHORIZED = (401, "未授权")
    FORBIDDEN = (403, "没有访问权限")
    NOT_FOUND = (404, "没有获取到数据")
    METHOD_NOT_ALLOWED = (405, "不支持当前请求类型")
    TOO_MANY_REQUESTS = (429, "请求过于频繁")
    INTERNAL_SERVER_ERROR = (500, "服务器内部错误")
    BAD_GATEWAY = (502, "网关错误")

    # ========== 自定义错误 ========== #
    ERR_BUSINESS = (1010, "业务异常")
    ERR_ARGUMENT = (1020, "参数错误")

    ERR_REQUEST_PARAM_VALIDATION_EXCEPTION = (2012, "请求参数校验异常")

    ERR_SAME_TOKEN = (10301, "提供的 Same-Token 是无效的")

    def __init__(self, code: int, message: str):
        self.code = code
        self.message = message


class TokenErrorEnum(Enum):
    """
    token 错误码枚举
    """
    NOT_TOKEN = (11011, -1, "未能读取到有效 token")
    INVALID_TOKEN = (11012, -2, "token 无效")
    TOKEN_TIMEOUT = (11013, -3, "token 已过期")
    BE_REPLACED = (11014, -4, "token 已被顶下线")
    KICK_OUT = (11015, -5, "token 已被踢下线")
    TOKEN_FREEZE = (11016, -6, "token 已被冻结")
    NO_PREFIX = (11017, -7, "未按照指定前缀提交 token")

    def __init__(self, code: int, type_: int, message: str):
        self.code = code
        self.type_ = type_
        self.message = message
